package com.xizi.leetcode周赛;

import java.util.Scanner;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-7-10下午 07:37
 */
public class _3758_距离零点的时刻 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n-- > 0) {
            int h = scanner.nextInt();
            int m = scanner.nextInt();
            System.out.println((23 - h) * 60 + (60 - m));
        }

    }
}
